<?php

namespace App\Service\Index\v1_1_0;

use App\Model\Banner;
use App\Service\BaseService;
use App\Service\ServiceTrait\GetUserInfoTrait;

class BannerService extends BaseService
{
    use GetUserInfoTrait;

    public function handle()
    {
        $ret = ['list' => []];

        $userId = $this->getUserId();
        $platform = $this->request->input('platform', 1);
        $channel = $this->request->input('channel', '');

        $profile = $this->getUserInfo($userId);

        $data = Banner::getListV1((int)$platform, (int)$profile->gender, (string)$channel);

        array_walk($data, function ($item) use (&$ret, $profile) {
            $ret['list'][] = Banner::packBanner($item, $profile);
        });
        return $ret;
    }
}